﻿using Nop.Core.Domain.Customers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Core.Domain.Logistics
{
    /// <summary>
    /// Represents a logisitics plan
    /// </summary>
    public class LogisticsPlan : BaseEntity
    {
        private ICollection<LogisticsLocation> _assignedLocations;
        private ICollection<PlanNote> _planNotes;

        /// <summary>
        /// Gets or sets the plan status
        /// </summary>
        public PlanStatus Status { get; set; }

        /// <summary>
        /// Gets or sets the courier identifier
        /// </summary>
        public int? CourierId { get; set; }

        /// <summary>
        /// Gets or sets the owner identifier
        /// </summary>
        public int? CustomerId { get; set; }

        /// <summary>
        /// Gets or sets the name of the plan
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the warehouse identifier
        /// </summary>
        public int? WarehouseId { get; set; }
        
        /// <summary>
        /// Gets or sets the district identifier
        /// </summary>
        public int? DistrictId { get; set; }

        /// <summary>
        /// Gets or sets if packages have been marked delivering
        /// </summary>
        public bool MarkedDelivering { get; set; }

        /// <summary>
        /// Gets or sets the courier 
        /// </summary>
        public virtual LogisticsCourier Courier { get; set; }

        /// <summary>
        /// Gets or sets the warehouse 
        /// </summary>
        public virtual LogisticsWarehouse Warehouse { get; set; }

        /// <summary>
        /// Gets or sets the district 
        /// </summary>
        public virtual District District { get; set; }

        /// <summary>
        /// Gets or sets the owner this plan is currently belonged to
        /// </summary>
        public virtual Customer Customer { get; set; }

        /// <summary>
        /// Gets or sets assigned locations
        /// </summary>
        public virtual ICollection<LogisticsLocation> AssignedLocations 
        {
            get { return _assignedLocations ?? (_assignedLocations = new List<LogisticsLocation>()); }
            protected set { _assignedLocations = value; }
        }

        /// <summary>
        /// Gets or sets plan notes
        /// </summary>
        public virtual ICollection<PlanNote> PlanNotes
        {
            get { return _planNotes ?? (_planNotes = new List<PlanNote>()); }
            protected set { _planNotes = value; }
        }
    }

    public enum PlanStatus : byte
    {
        Locked = 0, // Checked out plan, cannot be modified except the owner
        Running = 1, // Validated plan with locations and courier
        Closed = 2, // Closed
        Draft = 3 // Draft plan or package group. Not validate yet
    }
}
